package com.bustle.ejb.service;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.bustle.ejb.entity.Provider;
import com.bustle.ejb.service.dao.ProviderDao;

@Local
public interface ProviderManager {
	
	public List<Provider> getListProvider();
	public Provider getById (int idProvider);
	
	@Stateless
	public class DefaultProviderManager implements ProviderManager{
		@PersistenceContext
		protected EntityManager entityManager;
		
		@EJB
		private ProviderDao providerDao;

		@Override
		public List<Provider> getListProvider() {
			return providerDao.retrieveAll();
		}

		@Override
		public Provider getById(int idProvider) {
			List<Provider>  list = entityManager.createQuery("from  Provider").getResultList();
			Provider provider = list.get(0);
			return provider;
		}
		
	}

}
